LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
你的利用应该调用这个函数,而不是标准的main()函数。当你用clang和libfuzzer支持编译你的程序时,它将调用它的main函数,然后它将调用LLVMFuzzerTestOneInput函数与变异的数据。
这个函数需要2个参数:
Data - this is the actual fuzzed or mutated data which will be passed to API you want to fuzz.
Size - size of the Data.
最新版本的clang已经内置了libfuzzer,你只需要安装clang。
sudo apt install clang
clang -g -O1 -fsanitize=fuzzer mytarget.c # Builds the fuzz target w/o sanitizers
clang -g -O1 -fsanitize=fuzzer,address mytarget.c # Builds the fuzz target with ASAN
clang -g -O1 -fsanitize=fuzzer,signed-integer-overflow mytarget.c # Builds the fuzz target with a part of UBSAN
clang -g -O1 -fsanitize=fuzzer,memory mytarget.c # Builds the fuzz target with MSAN
使用下面的命令来编译它:
clang -fsanitize=fuzzer,address,undefined -g imgRead_libfuzzer.c -o imgRead_libfuzzer
./imgRead_libfuzzer
来源和参考资料: https://llvm.org/docs/LibFuzzer.html